package com.blb.demo3;

import java.time.LocalDateTime;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 线程池案例
 * 可调度的线程池
 */
public class ExecutorDemo4 {

    public static void testNewCachedThreadPool() {
        //创建可调度的线程池
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
        //执行可以调度的任务 任务 初始延迟日期 周期 时间单位
        scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println(LocalDateTime.now());
            }
        },0,1, TimeUnit.SECONDS);

//        scheduledExecutorService.shutdown();
    }

    public static void main(String[] args) {
        testNewCachedThreadPool();
    }

}
